{ config, pkgs, lib, ... }:
let
  # bash script to let dbus know about important env variables and
  # propagate them to relevent services run at the end of sway config
  dbus-sway-environment = pkgs.writeTextFile {
    name = "dbus-sway-environment";
    destination = "/bin/dbus-sway-environment";
    executable = true;

    text = ''
      dbus-update-activation-environment --systemd WAYLAND_DISPLAY XDG_CURRENT_DESKTOP=sway
  		systemctl --user stop pipewire pipewire-media-session xdg-desktop-portal xdg-desktop-portal-wlr
  		systemctl --user start pipewire pipewire-media-session xdg-desktop-portal xdg-desktop-portal-wlr
    '';
  };

  # currently, there is some friction between sway and gtk:
  # https://github.com/swaywm/sway/wiki/GTK-3-settings-on-Wayland
  # the suggested way to set gtk settings is with gsettings
  # for gsettings to work, we need to tell it where the schemas are
  # using the XDG_DATA_DIR environment variable
  # run at the end of sway config
  
in {
  environment.systemPackages = with pkgs; [
    kitty
    kitty-themes
    sway
    dbus-sway-environment
    wayland
    xdg-utils # for opening default programs when clicking links
    xdragon
    glib # gsettings
    dracula-theme # gtk theme
    qt5ct
    unstable.dracula-icon-theme
    gnome3.adwaita-icon-theme # default gnome cursors
    swaylock
    swayidle
    swaybg
    power-profiles-daemon

    grim # screenshot functionality
    slurp # screenshot functionality
    swayimg # picture viewer

    wl-clipboard # wl-copy and wl-paste for copy/paste from stdin/stdout
    wofi # wayland copy of rofi
    # mako # notificaition system
    swaynotificationcenter # GTK notification daemon for Sway
    wdisplays # tool to configure displays
    waybar
    networkmanagerapplet
    blueman
    udisks
  ];

  services.pipewire = {
    enable = true;
    alsa.enable = true;
    pulse.enable = true;
  };

  # xdg-desktop-portal works by exposing a series of D-Bus intefraces
  # known as portals under a well-known name
  # The portal interfaces include APIs for file access, opening URIs,
  # printing and others.
  services.dbus.enable = true;
  xdg.portal = {
    enable = true;
    wlr.enable = true;
    # gtk portal need to make gtk apps happy
    extraPortals = [ pkgs.xdg-desktop-portal-gtk ];
  };

  # enable sway window manager
  programs.sway = {
    enable = true;
    wrapperFeatures.gtk = true;
    # extraPackages = {
    #   
    # };
  };

  # For brightness
  programs.light.enable = true;

  services.dbus.packages = [ pkgs.blueman ];
  systemd.packages = [ pkgs.blueman ];
}
